package com.sanhuo.idms.service;

import com.sanhuo.idms.dao.DormElectricMapper;
import com.sanhuo.idms.dao.TungMapper;
import com.sanhuo.idms.entity.Tung;
import com.sanhuo.idms.vo.TungComsumeAnalysisVO;
import com.sanhuo.lib.ExceptionUtil;
import com.sanhuo.security.UserVo;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.Basic.BaseService;
import com.sanhuo.triild.annotation.MapperWire;
import com.sanhuo.utils.basic.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TungService extends BaseService<Tung> {

    @MapperWire
    private TungMapper tungMapper;

    @Override
    public BaseMapper<Tung> getBaseMapper() {
        return tungMapper;
    }

    public void save(final UserVo user, Integer tungNum) {
        ExceptionUtil.throwException(tungMapper.countByNum(tungNum) > 0, "已存在此栋(" + tungNum + "),请不要重复添加!");
        Tung tung = new Tung();
        tung.setId(StringUtil.UUID());
        tung.setNum(tungNum);
        tung.creatorAndUpdatorInfo(user);
        save(tung);
    }


}
